package com.five.api.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.five.api.service.CommentService;
import com.five.controller.BaseController;
import com.five.entity.Comment;
import com.five.qo.ArticleCollectionQO;
import com.five.qo.ArticleCommentQO;
import com.five.vo.BaseResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 博客评论表 前端控制器
 * </p>
 *
 * @author star
 * @since 2021-06-16
 */
@RestController
@CrossOrigin
@RequestMapping("comment")
@Api(tags = "查询用户的评论文章接口")
public class CommentController extends BaseController {

    @Autowired
    private CommentService commentService;

    @PostMapping("selectCommentById")
    @ApiOperation(value = "查询收藏文集接口")
    public BaseResultVO selectCommentById(@ApiParam(value = "用户id") @RequestParam("userId") Long userId){
        if (userId==0 || userId==null){
            return errorResp("用户id为空");
        }

        List<ArticleCommentQO> articleComments = commentService.selectCommentByUserId(userId);

        return successResp(articleComments);
    }

    @ApiOperation(value = "分页获取评论列表")
    @GetMapping("getCommentsWithPage")
    public BaseResultVO getCommentsWithPage(Long articleId, Long current){
        Page<Comment> commentsPage = commentService.getCommentsByArticleIdWithPage(articleId, current);
        return successResp(commentsPage);
    }

    @ApiOperation(value = "删除评论")
    @PostMapping("deleteComment")
    public BaseResultVO deleteComment(Long id){
        commentService.deleteComment(id);
        return successRespWithMessage("删除评论成功");
    }

    @ApiOperation(value = "发布评论")
    @PostMapping("insertComment")
    public BaseResultVO insertComment(Comment comment){
        commentService.insertComment(comment);
        return successRespWithMessage("发布评论成功");
    }
}
